/**
 * This is a wrapper class for Comparable objects that will count how many times
 * the compareTo method of that object is called
 * 
 * @param <T>
 *            a comparable object type
 */
public abstract class MyComparable<T extends Comparable<? super T>> implements Comparable<MyComparable<T>>{
		
	private static int comparisons = 0;

	public static int comparisons() {
		return comparisons;
	}

	public static void reset() {
		comparisons = 0;
	}

	private final T data;

	public MyComparable(T data) {
		this.data = data;
	}

	public int compareTo(MyComparable<T> that) {
		comparisons++;
		// null is treated as positive infinity
		if (that == null)
			return -1;
		if (data == null && that.data == null)
			return 0;
		if (data == null)
			return 1;
		if (that.data == null)
			return -1;
		return data.compareTo(that.data);
	}
	
	@Override
	public String toString() {
		return data == null ? "null" : data.toString();
	}
}
